package fr.esiea.erg5203.mvc.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import fr.esiea.erg5203.business.Contact;
import fr.esiea.erg5203.persistence.dao.AbstractDAOFactory;
import fr.esiea.erg5203.persistence.dao.DAO;

@Controller  
@RequestMapping(value = "/index.jsp")
public class ReadController {
	
	@RequestMapping(params = "action=read")
	public ModelAndView read(HttpServletRequest request)
	{		
		String id = request.getParameter("id");	
		DAO<Contact> contactDAO = AbstractDAOFactory.getDAOFactory().getContactDAO();				
		ModelAndView result = new ModelAndView("read");
				
		result.addObject("contact", contactDAO.find(Integer.parseInt(id)));
		
		System.out.println("Read Meth");
		return result;
	}		
}
